package com.example.demo;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@ServletComponentScan //使用此注解后Servlet、Filter(过滤器)、Listener(监听器)可以直接通过@WebServlet、@WebFilter、@WebListener注解自动注册
public class PracticeApplication extends SpringBootServletInitializer {


    @Autowired
    private RestTemplateBuilder restTemplateBuilder;

    @Bean
    public RestTemplate build() {
        return restTemplateBuilder.build();
    }

    public static void main(String[] args) {
        SpringApplication.run(PracticeApplication.class, args);
    }

    /**
     * 返回jsp页面所需要的重写
     *
     * @param builder
     * @return
     */
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(PracticeApplication.class);
    }
    private static BeanFactory beanFactory = null;
    public static <T> T getBean(String name){
        return (T) beanFactory.getBean(name);
    }
    
}
